package we.common;

import java.io.PrintWriter;
import java.io.StringWriter;
import we.logcontroller.ILogController.LogMode;
import we.logcontroller.scribe.CScribeLogController;

public class CCommonHandle
{

    private CCommonHandle()
    {
    }

    public static void writeActionLog(String ownerId, String victimId,
            String ipOrUrl, String action,
            String param1, String param2,
            String param3, String param4,
            String param5, int goldChange,
            int xuChange, int expChange)
    {

        String data =
                ownerId + "|" + victimId + "|" + ipOrUrl + "|" + action + "|"
                + param1 + "|" + param2 + "|" + param3 + "|" + param4 + "|"
                + param5 + "|" + goldChange + "|" + xuChange + "|" + expChange;

        new CScribeLogController().writeLog(LogMode.ACTION, data);
    }

    public static void writeErrLog(Throwable t)
    {
        new CScribeLogController().writeLog(LogMode.ERROR, getStackTrace(t));
        t.printStackTrace();
    }

    private static String getStackTrace(Throwable t)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        t.printStackTrace(pw);
        pw.flush();
        sw.flush();
        return sw.toString();
    }
}
